#!/bin/bash
node="$1"
src_mgmt="./mgmtd/build/orcafs-mgmtd"

if (( $# != 1)); then
	echo "Uasge: sh $0 <96.100>"
	exit
fi

if [ ! -e ${src_mgmt} ]; then
    echo "file(${src_mgmt}) is not exist"
	echo "Uasge: sh $0 <96.100>"
	exit
fi

dest_mgmt="/opt/orcafs/sbin/orcafs-mgmtd"

function update_mgmt()
{
    echo -------------"${node}"----"${src_mgmt}"---stop---
    sshpass -p 'p@ssword' ssh root@192.168."${node}" 'systemctl stop orcafs-mgmtd'
    sshpass -p 'p@ssword' scp ${src_mgmt} root@192.168."${node}":${dest_mgmt}
    sshpass -p 'p@ssword' ssh root@192.168."${node}" 'systemctl start orcafs-mgmtd'
    echo -------------"${node}"----"${src_mgmt}"---start----
    eval sshpass -p 'p@ssword' ssh root@192.168."${node}" 'systemctl status orcafs-mgmtd | grep Active'
}

update_mgmt
